package com.talent.core.protocol.websocket.zk;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @ClassName：CuratorConfig
 * @Author: hszhou
 * @Date: 2024/12/9 17:51
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class CuratorConfig {

    private static String host="172.28.33.102:2181";//单机集群 ip:port
    private static Integer connectTimeoutMs=30*1000;//连接超时时间
    private static Integer sessionTimeoutMs=3*1000;//会话链接时间
    private static Integer sleepMsBetweenRetry=2*1000;//每次重试的间隔时间
    private static Integer maxRetries=3;//最大重试次数
    private static String namespace="talent";//命名空间（root根节点名称）

    private static CuratorFramework client;

    static {

        //订阅重试次数
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(sleepMsBetweenRetry,maxRetries);

        //声明初始化客户端
        client= CuratorFrameworkFactory.builder()
                .connectString(host)
                .connectionTimeoutMs(connectTimeoutMs)
                .sessionTimeoutMs(sessionTimeoutMs)
                .retryPolicy(retryPolicy)
                .namespace(namespace)
                .build();

        //启动
        client.start();
    }

    public static CuratorFramework getClient(){
        return client;
    }
}
